package com.sojoys.artifact.tools;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListSet;

/**
 * 此处主要为生成的缓存设计
 * 选择 ConcurrentSkipListSet 是因为redis，或对象释放等情况会影响。查询的排序
 * @author win7
 *
 * @param <K>
 * @param <V>
 */
public class SetMap<K, V> extends ConcurrentHashMap<K, ConcurrentSkipListSet<V>>{
	private static final long serialVersionUID = 1L;

	public ConcurrentSkipListSet<V> getIfAbsent(K key){
		ConcurrentSkipListSet<V> v = super.get(key);
		if (v == null) {
			v = new ConcurrentSkipListSet<V>();
			super.put(key, v);
		}
		return v;
	}
	
	public boolean setRemove(K k,V v){
		boolean isRemove = false;
		ConcurrentSkipListSet<V> set = super.get(k);
		if (set!=null) {
			isRemove = set.remove(v);
		}
		return isRemove;
	}
}
